'use strict';

// 接收到数据调用
module.exports = app => {
  class Controller extends app.Controller {
    async message() {
      const { app, socket } = this.ctx;
      const nsp = app.io.of('/chat');
      // 接收到的参数
      const messageData = this.ctx.args[0];
      const data = {
        ...messageData,
        date: new Date(),
        current: socket.id,
      };
      this.ctx.service.message.add(data);
      nsp.to('WEB').emit('message', data);
    }
  }
  return Controller;
};

